package com.lixl.collection;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;

public class MapDemo {

	public static void main(String[] args) {
		treeMapTest();
	}
	
	public static void hashMapTest(){
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("k1", "kkk1");
		map.put("k2", "kkkk2");
		map.put("k3", "kkkk3");
		map.put("k4", "kkkk4");
		System.out.println("=========hashMapTest=========");
		for (Entry<String, String> e : map.entrySet()) {
			System.out.println(e.getKey()+"="+e.getValue());
		}
	}
	
	public static void linkedHashMapTest(){
		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		map.put("k1", "kkk1");
		map.put("k2", "kkkk2");
		map.put("k3", "kkkk3");
		map.put("k4", "kkkk4");
		
		System.out.println("=========linkedHashMapTest=========");
		for (Entry<String, String> e : map.entrySet()) {
			System.out.println(e.getKey()+"="+e.getValue());
		}
	}
	
	/**
	 * 
	 */
	public static void concurrentHashMapTest(){
		ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<String, Object>();
		map.put("k1", 123);
		
	}
	
	public static void hashTableTest(){
		Hashtable<String, Object> map = new Hashtable<String, Object>();
		map.put("1", "v1");
		System.out.println(map);
	}
	
	public static void treeMapTest(){
		TreeMap<String, Object> map = new TreeMap<String, Object>();
		map.put("1001", "zhangs");
		map.put("1002", "kdfdk");
		map.put("1005", "hxxx");
		map.put("1003", "ldmf");
		map.put("1004", "fghg");
		
		for (String key:map.descendingKeySet()) {
			System.out.println(key+"="+map.get(key));
		}
	}
	
	public static void weakHashMapTest(){
		WeakHashMap<String, Object> map = new WeakHashMap<String, Object>();
		map.put("23", new Long("232424242"));
		
		System.out.println(map);
	}
	
}
